package com.thread.auxiliaryClassUse;

import java.util.concurrent.CountDownLatch;

/**
 * 多个线程等待：模拟并发，让并发线程一起执行
 */
public class CountDownLatchTest02 {

    static final CountDownLatch countDownLatch = new CountDownLatch(1);

    public static void main(String[] args) throws InterruptedException {
        for (int i = 0; i < 5; i++) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        System.out.println(Thread.currentThread().getName() + "子线程开始准备……");
                        countDownLatch.await();
                        System.out.println(Thread.currentThread().getName() + "子线程准备完毕……");
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }).start();
        }
        Thread.sleep(2000);
        countDownLatch.countDown();
    }
}
